﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Platform.ObjectModel.Design;

namespace Platform.ObjectModel.Rules
{
	/// <summary>
	/// Verifica se a propriedade possui um valor
	/// </summary>
	public class Required : RuleBase
	{
		private static readonly DataObjectName Name = DataObjectName.From( typeof( Required ) );

		public Required()
			: base( Name )
		{ }

		public override bool Validate( dynamic value, DocumentContext context )
		{
			if ( value == null )
				return false;

			if ( value is IEnumerable )	// Quando é string, também vai entrar aqui e verificar se possui caracteres
				return ( ( IEnumerable<object> )value ).Any();
			else 
				return true;
		}
	}
}
